X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/097781e6ad3f7bb1c13c16ff7b6bb7219764fb29..b587e9d8e0cc5eb1edf972fd3b644704441e5289:/Super%20Polarity/Actors/MainShip.cs diff --git a/Super Polarity/Actors/MainShip.cs b/Super Polarity/Actors/MainShip.cs index 616f16e..9f28c80 100644 --- a/Super Polarity/Actors/MainShip.cs +++ b/Super Polarity/Actors/MainShip.cs @@ -6,6 +6,7 @@ using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Audio; namespace SuperPolarity { @@ -24,6 +25,10 @@ namespace SuperPolarity protected float MaxImmortalTime; protected bool Flashing; + protected SoundEffect PolarityChange; + protected SoundEffect ShootSound; + protected SoundEffect Hit; + public MainShip(SuperPolarity newGame) : base(newGame) {} ~MainShip() @@ -35,12 +40,18 @@ namespace SuperPolarity { base.Initialize(texture, position); - MainShip.BlueColor = new Color(230, 244, 249); - MainShip.RedColor = new Color(255, 234, 241); + MainShip.BlueColor = new Color(0, 184, 229); + MainShip.RedColor = new Color(201, 0, 68); + + PolarityChange = game.Content.Load("Sound\\polaritychange"); + ShootSound = game.Content.Load("Sound\\bullet"); + Hit = game.Content.Load("Sound\\hit"); InitParticleEngine(); SetPolarity(Polarity.Positive); + ActVelocity = 2.5f; + ShotCooldown = 50; MaxImmortalTime = 1500; @@ -68,19 +79,28 @@ namespace SuperPolarity protected void HandleShot(float value) { + + Shooting = true; + Timer t = new Timer(new TimerCallback(UnlockShot)); + t.Change(ShotCooldown, Timeout.Infinite); + + if (Children.Count > 10) + { + return; + } + var bullet = ActorFactory.CreateBullet(Position, Angle); Children.Add(bullet); bullet.Parent = this; - Shooting = true; - Timer t = new Timer(new TimerCallback(UnlockShot)); - t.Change(ShotCooldown, Timeout.Infinite); + ShootSound.Play(); } protected void UnlockShot(object state) { InputController.Unlock("shoot"); + Shooting = false; } protected void HandleChangePolarity(float value) @@ -90,28 +110,29 @@ namespace SuperPolarity public void HandleHorizontalMovement(float value) { - Acceleration.X = value * AccelerationRate; - - if (value > 0.1 && Velocity.X < 0 || value < 0.1 && Velocity.X > 0) + if (value >= -0.5 && value <= 0.5) { - Acceleration.X *= 2; + value = 0; } - if (value > 0.1 && Velocity.Y < 0 || value < 0.1 && Velocity.Y > 0) - { - Acceleration.Y *= 2; - } + Velocity.X = value * MaxVelocity; } public void HandleVerticalMovement(float value) { - Acceleration.Y = value * AccelerationRate; + if (value >= -0.5 && value <= 0.5) + { + value = 0; + } + + Velocity.Y = value * MaxVelocity; } public override void SwitchPolarity() { base.SwitchPolarity(); SwitchParticleEngine(CurrentPolarity); + PolarityChange.Play(); game.Player.ResetMultiplier(); } @@ -144,7 +165,6 @@ namespace SuperPolarity particleEngine.Update(); ConstrainToEdges(); UpdateImmortality(gameTime); - Shooting = false; } public void UpdateImmortality(GameTime gameTime) @@ -174,30 +194,36 @@ namespace SuperPolarity public override void Move(GameTime gameTime) { - base.Move(gameTime); + var VelocityLimit = MaxVelocity; + var SavedVelocity = new Vector2(Velocity.X, Velocity.Y); if (Shooting) { - if (Velocity.X > ActVelocity) - { - Velocity.X = ActVelocity; - } + VelocityLimit = ActVelocity; + } - if (Velocity.X < -ActVelocity) - { - Velocity.X = -ActVelocity; - } + if (SavedVelocity.X > VelocityLimit) + { + SavedVelocity.X = VelocityLimit; + } - if (Velocity.Y > ActVelocity) - { - Velocity.Y = ActVelocity; - } + if (SavedVelocity.X < -VelocityLimit) + { + SavedVelocity.X = -VelocityLimit; + } - if (Velocity.Y < -ActVelocity) - { - Velocity.Y = -ActVelocity; - } + if (SavedVelocity.Y > VelocityLimit) + { + SavedVelocity.Y = VelocityLimit; + } + + if (SavedVelocity.Y < -VelocityLimit) + { + SavedVelocity.Y = -VelocityLimit; } + + Position.X = Position.X + SavedVelocity.X; + Position.Y = Position.Y + SavedVelocity.Y; } public override void Magnetize(Ship ship, float distance, float angle) @@ -266,11 +292,23 @@ namespace SuperPolarity if (game.Player.Lives < 0) { Dying = true; + game.GameOver(); } else { + Hit.Play(); Immortal = true; CurrentImmortalTime = 0; } } + + public override void CleanUp() + { + base.CleanUp(); + particleEngine = null; + InputController.Unbind("moveX", HandleHorizontalMovement); + InputController.Unbind("moveY", HandleVerticalMovement); + InputController.Unbind("changePolarity", HandleChangePolarity); + InputController.Unbind("shoot", HandleShot); + } } }